/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.sisece.controlador;

import com.sisece.modelo.dato.Categoria;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;

/**
 *
 * @author laptop-w8
 */
@FacesConverter(value = "categoriaConverter01")
public class CategoriaConverter01 implements Converter {
    @Override
    public Object getAsObject(FacesContext fc, UIComponent uic, String string) {
        if (string == null || string.equals("")) {
            return null;
        }
        ProductoController re = (ProductoController) fc.getELContext().getELResolver().getValue(
                fc.getELContext(), null, "productoController");
        return (Categoria) re.getHmCategorias().get(string);
    }

    @Override
    public String getAsString(FacesContext fc, UIComponent uic, Object o) {
        if (o == null) {
            return "";
        }
        if (o instanceof Categoria) {
            Categoria a = (Categoria) o;
            return a.getNombre();
        } else {
            return "";
        }
    }


}
